//
//  ZQQDownLoader.h
//  ZQQDownLoader
//
//  Created by MoDao-iOS on 2017/7/17.
//  Copyright © 2017年 MoDao-iOS. All rights reserved.
//

#import <Foundation/Foundation.h>

// 下载状态变化通知
#define kDownLoadURLOrStateChangeNotification @"downLoadURLOrStateChangeNotification"

typedef NS_ENUM(NSUInteger, ZQQDownLoaderState) {
    /** 下载暂停 */
    ZQQDownLoaderStatePause,
    /** 正在下载 */
    ZQQDownLoaderStateDowning,
    /** 已经下载 */
    ZQQDownLoaderStateSuccess,
    /** 下载失败 */
    ZQQDownLoaderStateFailed
};

typedef void(^DownLoadInfoType)(long long totalSize);
typedef void(^ProgressBlockType)(float progress);
typedef void(^SuccessBlockType)(NSString *filePath);
typedef void(^FailedBlockType)();
typedef void(^StateChangeType)(ZQQDownLoaderState state);

@interface ZQQDownLoader : NSObject

- (void)downLoader:(NSURL *)url downLoadInfo:(DownLoadInfoType)downLoadInfo progress:(ProgressBlockType)progressBlock success:(SuccessBlockType)successBlock failed:(FailedBlockType)failedBlock;

/**
 根据URL地址下载资源, 如果任务已经存在, 则执行继续动作
 @param url 资源路径
 */
- (void)downLoader:(NSURL *)url;

// 下载好的文件路经
+ (NSString *)downLoadedFileWithURL: (NSURL *)url;
// 临时文件大小
+ (long long)tmpCacheSizeWithURL: (NSURL *)url;
// 清除缓存
+ (void)clearCacheWithURL: (NSURL *)url;

/**
 暂停任务
 注意:
 - 如果调用了几次继续
 - 调用几次暂停, 才可以暂停
 - 解决方案: 引入状态
 */
- (void)pauseCurrentTask;

// 继续任务
- (void)resumeCurrentTask;

/**
 取消任务
 */
- (void)cacelCurrentTask;

/**
 取消任务, 并清理资源
 */
- (void)cacelAndClean;


/// 事件&数据
/** 下载状态 */
@property (nonatomic, assign, readonly) ZQQDownLoaderState state;
@property (nonatomic, assign, readonly) float progress;

@property (nonatomic, copy) DownLoadInfoType downLoadInfo;
@property (nonatomic, copy) StateChangeType stateChange;
@property (nonatomic, copy) ProgressBlockType progressChange;
@property (nonatomic, copy) SuccessBlockType successBlock;
@property (nonatomic, copy) FailedBlockType faildBlock;

@end
